package dxsvalue

import (
	"encoding/json"
	"github.com/suiyunonghen/DxCommonLib"
	"reflect"
	"strconv"
	"strings"
	"time"
)

func decode2reflectFromdxValue(fvalue reflect.Value, value *DxValue, ignoreCase bool, valueType reflect.Type) {
	value.Visit(func(Key string, childvalue *DxValue) bool {
		for i := 0; i < valueType.NumField(); i++ {
			fld := valueType.Field(i)
			if ignoreCase && strings.EqualFold(Key, fld.Name) || Key == fld.Name {
				childreflectv := fvalue.Field(i)
				tp := fld.Type
				if tp.Implements(ValueUnMarshalerType) {
					childreflectv.Interface().(DxValueUnMarshaler).DecodeFromDxValue(childvalue)
					break
				}
				vhandler, ok := structTypePool.Load(tp)
				if ok && vhandler != nil {
					convertHandler := vhandler.(StdValueFromDxValue)
					if convertHandler != nil {
						convertHandler(childreflectv, childvalue)
						break
					}
				}
				switch tp.Kind() {
				case reflect.String:
					childreflectv.SetString(childvalue.String())
				case reflect.Int, reflect.Int64, reflect.Int8, reflect.Int16, reflect.Int32:
					childreflectv.SetInt(childvalue.Int())
				case reflect.Uint, reflect.Uint64, reflect.Uint8, reflect.Uint16, reflect.Uint32:
					childreflectv.SetUint(uint64(childvalue.Int()))
				case reflect.Float32, reflect.Float64:
					childreflectv.SetFloat(childvalue.Double())
				case reflect.Bool:
					childreflectv.SetBool(childvalue.Bool())
				case reflect.Slice:
					decodeArray2reflect(childreflectv, childvalue, ignoreCase)
				case reflect.Struct:
					if tp == TimeType {
						childreflectv.Set(reflect.ValueOf(childvalue.GoTime()))
					} else {
						decode2reflectFromdxValue(childreflectv, childvalue, ignoreCase, tp)
					}
				}
				break
			}
		}
		return true
	})
}

func growSliceValue(v reflect.Value, n int) reflect.Value {
	diff := n - v.Len()
	if diff > 256 {
		diff = 256
	}
	v = reflect.AppendSlice(v, reflect.MakeSlice(v.Type(), diff, diff))
	return v
}

func decodeArray2reflect(sliceValue reflect.Value, arrvalue *DxValue, ignoreCase bool) bool {
	if arrvalue.DataType != VT_Array {
		return false
	}
	n := arrvalue.Count()
	if n == 0 {
		return false
	}
	var vtype reflect.Type
	sliceCap := sliceValue.Cap()
	if sliceCap == 0 {
		vslice := reflect.MakeSlice(sliceValue.Type(), n, n)
		sv := vslice.Index(0)
		vtype = sv.Type()
		sliceValue.Set(vslice.Slice(0, n))
	} else if sliceCap >= n {
		vtype = sliceValue.Slice(1, 1).Field(0).Type()
		sliceValue.Set(sliceValue.Slice(0, n))
	} else if sliceValue.Len() < sliceValue.Cap() {
		vtype = sliceValue.Slice(1, 1).Field(0).Type()
		sliceValue.Set(sliceValue.Slice(0, sliceCap))
	}

	if vtype.Implements(ValueUnMarshalerType) {
		for i := 0; i < n; i++ {
			arrNode := arrvalue.ValueByIndex(i)
			if i >= sliceValue.Len() {
				sliceValue.Set(growSliceValue(sliceValue, n))
			}
			sliceValue.Field(i).Interface().(DxValueUnMarshaler).DecodeFromDxValue(arrNode)
		}
		return true
	}

	vhandler, ok := structTypePool.Load(vtype)
	if ok && vhandler != nil {
		convertHandler := vhandler.(StdValueFromDxValue)
		if convertHandler != nil {
			for i := 0; i < n; i++ {
				arrNode := arrvalue.ValueByIndex(i)
				if i >= sliceValue.Len() {
					sliceValue.Set(growSliceValue(sliceValue, n))
				}
				convertHandler(sliceValue.Field(i), arrNode)
			}
			return true
		}
	}

	if vtype == TimeType {
		for i := 0; i < n; i++ {
			arrNode := arrvalue.ValueByIndex(i)
			if i >= sliceValue.Len() {
				sliceValue.Set(growSliceValue(sliceValue, n))
			}
			sliceValue.Field(i).Set(reflect.ValueOf(arrNode.GoTime()))
		}
		return true
	}
	switch vtype.Kind() {
	case reflect.String:
		for i := 0; i < n; i++ {
			arrNode := arrvalue.ValueByIndex(i)
			if i >= sliceValue.Len() {
				sliceValue.Set(growSliceValue(sliceValue, n))
			}
			sliceValue.Index(i).SetString(arrNode.String())
		}
	case reflect.Int, reflect.Int64, reflect.Int8, reflect.Int16, reflect.Int32:
		for i := 0; i < n; i++ {
			arrNode := arrvalue.ValueByIndex(i)
			if i >= sliceValue.Len() {
				sliceValue.Set(growSliceValue(sliceValue, n))
			}
			sliceValue.Index(i).SetInt(arrNode.Int())
		}
	case reflect.Uint, reflect.Uint64, reflect.Uint8, reflect.Uint16, reflect.Uint32:
		for i := 0; i < n; i++ {
			arrNode := arrvalue.ValueByIndex(i)
			if i >= sliceValue.Len() {
				sliceValue.Set(growSliceValue(sliceValue, n))
			}
			sliceValue.Index(i).SetUint(uint64(arrNode.Int()))
		}
	case reflect.Float32, reflect.Float64:
		for i := 0; i < n; i++ {
			arrNode := arrvalue.ValueByIndex(i)
			if i >= sliceValue.Len() {
				sliceValue.Set(growSliceValue(sliceValue, n))
			}
			sliceValue.Index(i).SetFloat(arrNode.Double())
		}
	case reflect.Bool:
		for i := 0; i < n; i++ {
			arrNode := arrvalue.ValueByIndex(i)
			if i >= sliceValue.Len() {
				sliceValue.Set(growSliceValue(sliceValue, n))
			}
			sliceValue.Index(i).SetBool(arrNode.Bool())
		}
	case reflect.Slice:
		for i := 0; i < n; i++ {
			arrNode := arrvalue.ValueByIndex(i)
			if i >= sliceValue.Len() {
				sliceValue.Set(growSliceValue(sliceValue, n))
			}
			decodeArray2reflect(sliceValue.Index(i), arrNode, ignoreCase)
		}
	case reflect.Struct:
		for i := 0; i < n; i++ {
			arrNode := arrvalue.ValueByIndex(i)
			if i >= sliceValue.Len() {
				sliceValue.Set(growSliceValue(sliceValue, n))
			}

			decode2reflectFromdxValue(sliceValue.Index(i), arrNode, ignoreCase, vtype)
		}

	default:
		return false
	}
	return true
}

func (v *DxValue) SetValue(value interface{}) {
	if v == valueNAN || v == valueINF || v == valueTrue || v == valueFalse || v == valueNull {
		return
	}
	switch realv := value.(type) {
	case int:
		v.SetInt(int64(realv))
	case *int:
		v.SetInt(int64(*realv))
	case uint:
		v.SetInt(int64(realv))
	case *uint:
		v.SetInt(int64(*realv))
	case int32:
		v.SetInt(int64(realv))
	case *int32:
		v.SetInt(int64(*realv))
	case uint32:
		v.SetInt(int64(realv))
	case *uint32:
		v.SetInt(int64(*realv))
	case int16:
		v.SetInt(int64(realv))
	case *int16:
		v.SetInt(int64(*realv))
	case uint16:
		v.SetInt(int64(realv))
	case *uint16:
		v.SetInt(int64(*realv))
	case int8:
		v.SetInt(int64(realv))
	case *int8:
		v.SetInt(int64(*realv))
	case uint8:
		v.SetInt(int64(realv))
	case *uint8:
		v.SetInt(int64(*realv))
	case int64:
		v.SetInt(realv)
	case *int64:
		v.SetInt(*realv)
	case uint64:
		v.SetInt(int64(realv))
	case *uint64:
		v.SetInt(int64(*realv))
	case string:
		v.SetString(realv)
	case *DxValue:
		v.CopyFrom(realv, nil)
	case DxValue:
		v.CopyFrom(&realv, nil)
	case bool:
		v.SetBool(realv)
	case *bool:
		v.SetBool(*realv)
	case time.Time:
		v.SetDouble(float64(DxCommonLib.Time2DelphiTime(realv)))
	case *time.Time:
		v.SetDouble(float64(DxCommonLib.Time2DelphiTime(*realv)))
	case float32:
		v.SetFloat(realv)
	case *float32:
		v.SetFloat(*realv)
	case float64:
		v.SetDouble(realv)
	case *float64:
		v.SetDouble(*realv)
	case []byte:
		v.SetBinary(realv, true)
	case *[]byte:
		v.SetBinary(*realv, true)
	case map[string]interface{}:
		v.Reset(VT_Object)
		cache := v.ValueCache()
		for key, objv := range realv {
			v.SetKeyvalue(key, objv, cache)
		}
	case *map[string]interface{}:
		v.Reset(VT_Object)
		cache := v.ValueCache()
		for key, objv := range *realv {
			v.SetKeyvalue(key, objv, cache)
		}
	case map[string]string:
		v.Reset(VT_Object)
		cache := v.ValueCache()
		for key, objv := range realv {
			v.SetKeyCached(key, VT_String, cache).SetString(objv)
		}
	case *map[string]string:
		v.Reset(VT_Object)
		cache := v.ValueCache()
		for key, objv := range *realv {
			v.SetKeyCached(key, VT_String, cache).SetString(objv)
		}
	case map[string]int:
		v.Reset(VT_Object)
		cache := v.ValueCache()
		for key, objv := range realv {
			v.SetKeyCached(key, VT_Int, cache).SetInt(int64(objv))
		}
	case *map[string]int:
		v.Reset(VT_Object)
		cache := v.ValueCache()
		for key, objv := range *realv {
			v.SetKeyCached(key, VT_Int, cache).SetInt(int64(objv))
		}
	case []interface{}:
		v.Reset(VT_Array)
		cache := v.ValueCache()
		for i := 0; i < len(realv); i++ {
			v.SetIndexvalue(i, realv[i], cache)
		}
	case *[]interface{}:
		v.Reset(VT_Array)
		cache := v.ValueCache()
		for i := 0; i < len(*realv); i++ {
			v.SetIndexvalue(i, (*realv)[i], cache)
		}
	case []string:
		v.Reset(VT_Array)
		cache := v.ValueCache()
		for i := 0; i < len(realv); i++ {
			v.SetIndexCached(i, VT_String, cache).SetString(realv[i])
		}
	case *[]string:
		v.Reset(VT_Array)
		cache := v.ValueCache()
		for i := 0; i < len(*realv); i++ {
			v.SetIndexCached(i, VT_String, cache).SetString((*realv)[i])
		}
	default:
		//判断一下是否是结构体
		reflectv := reflect.ValueOf(value)
		if !reflectv.IsValid() {
			return
		}
		if reflectv.Type().Implements(ValueMarshalerType) {
			value.(DxValueMarshaler).EncodeToDxValue(v)
			return
		}
		if reflectv.Kind() == reflect.Ptr {
			reflectv = reflectv.Elem()
		} /*else if reflect.PtrTo(reflectv.Type()).Implements(ValueMarshalerType){
			value.(DxValueMarshaler).EncodeToDxValue(v)
			return
		}*/
		switch reflectv.Kind() {
		case reflect.Struct:
			tp := reflectv.Type()
			if tp == TimeType {
				vi := reflectv.Interface()
				v.SetTime(vi.(time.Time))
				return
			} else if tp == TimePtrType {
				vi := reflectv.Interface()
				v.SetTime(*(vi.(*time.Time)))
				return
			}
			v.Reset(VT_Object)
			cache := v.ValueCache()
			rtype := reflectv.Type()
			for i := 0; i < rtype.NumField(); i++ {
				sfield := rtype.Field(i)
				fv := reflectv.Field(i)
				if fv.Kind() == reflect.Ptr {
					fv = fv.Elem()
				}
				switch fv.Kind() {
				case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
					reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
					v.SetKeyCached(sfield.Name, VT_Int, cache).SetInt(fv.Int())
				case reflect.Bool:
					if fv.Bool() {
						v.SetKeyValue(sfield.Name, valueTrue)
					} else {
						v.SetKeyValue(sfield.Name, valueFalse)
					}
				case reflect.Float32:
					v.SetKeyCached(sfield.Name, VT_Double, cache).SetFloat(float32(fv.Float()))
				case reflect.Float64:
					v.SetKeyCached(sfield.Name, VT_Double, cache).SetDouble(fv.Float())
				case reflect.String:
					v.SetKeyCached(sfield.Name, VT_String, cache).SetString(fv.String())
				default:
					if fv.CanInterface() {
						fvtp := fv.Type()
						if fvtp.Implements(ValueMarshalerType) {
							fv.Interface().(DxValueMarshaler).EncodeToDxValue(v.SetKeyCached(sfield.Name, VT_Int, cache))
						} else if fvtp == TimeType {
							v.SetKeyCached(sfield.Name, VT_DateTime, cache).SetTime(fv.Interface().(time.Time))
						} else if fvtp == TimePtrType {
							v.SetKeyCached(sfield.Name, VT_DateTime, cache).SetTime(*(fv.Interface().(*time.Time)))
						} else {
							v.SetKeyvalue(sfield.Name, fv.Interface(), cache)
						}
					}
				}
			}
		case reflect.Map:
			mapRange := reflectv.MapRange()
			if !mapRange.Next() {
				return
			}
			key := mapRange.Key()
			if key.Kind() == reflect.Ptr {
				key = key.Elem()
			}
			v.Reset(VT_Object)
			cache := v.ValueCache()
			kind := key.Kind()
			switch kind {
			case reflect.String:
				_fillMapItem2DxValue(v, key.String(), mapRange.Value(), cache)
				for mapRange.Next() {
					key = mapRange.Key()
					if key.Kind() == reflect.Ptr {
						key = key.Elem()
					}
					_fillMapItem2DxValue(v, key.String(), mapRange.Value(), cache)
				}
			case reflect.Int, reflect.Int32, reflect.Int16, reflect.Int8, reflect.Int64:
				_fillMapItem2DxValue(v, strconv.FormatInt(key.Int(), 10), mapRange.Value(), cache)
				for mapRange.Next() {
					key = mapRange.Key()
					if key.Kind() == reflect.Ptr {
						key = key.Elem()
					}
					_fillMapItem2DxValue(v, strconv.FormatInt(key.Int(), 10), mapRange.Value(), cache)
				}
			case reflect.Uint, reflect.Uint32, reflect.Uint16, reflect.Uint8, reflect.Uint64:
				_fillMapItem2DxValue(v, strconv.FormatUint(key.Uint(), 10), mapRange.Value(), cache)
				for mapRange.Next() {
					key = mapRange.Key()
					if key.Kind() == reflect.Ptr {
						key = key.Elem()
					}
					_fillMapItem2DxValue(v, strconv.FormatUint(key.Uint(), 10), mapRange.Value(), cache)
				}
			}
		case reflect.Slice:
			v.Reset(VT_Array)
			cache := v.ValueCache()
			vlen := reflectv.Len()
			for i := 0; i < vlen; i++ {
				av := reflectv.Index(i)
				realvalue := getRealValue(&av)
				if realvalue == nil {
					v.SetIndexCached(i, VT_NULL, cache)
				} else if realvalue.CanInterface() {
					v.SetIndexvalue(i, realvalue.Interface(), cache)
				}
			}
		}

	}
}

func (v *DxValue) SetKeyvalue(Name string, value interface{}, cache *ValueCache) {
	switch realv := value.(type) {
	case int:
		v.SetKeyCached(Name, VT_Int, cache).SetInt(int64(realv))
	case *int:
		v.SetKeyCached(Name, VT_Int, cache).SetInt(int64(*realv))
	case uint:
		v.SetKeyCached(Name, VT_Int, cache).SetInt(int64(realv))
	case *uint:
		v.SetKeyCached(Name, VT_Int, cache).SetInt(int64(*realv))
	case int32:
		v.SetKeyCached(Name, VT_Int, cache).SetInt(int64(realv))
	case *int32:
		v.SetKeyCached(Name, VT_Int, cache).SetInt(int64(*realv))
	case uint32:
		v.SetKeyCached(Name, VT_Int, cache).SetInt(int64(realv))
	case *uint32:
		v.SetKeyCached(Name, VT_Int, cache).SetInt(int64(*realv))
	case int16:
		v.SetKeyCached(Name, VT_Int, cache).SetInt(int64(realv))
	case *int16:
		v.SetKeyCached(Name, VT_Int, cache).SetInt(int64(*realv))
	case uint16:
		v.SetKeyCached(Name, VT_Int, cache).SetInt(int64(realv))
	case *uint16:
		v.SetKeyCached(Name, VT_Int, cache).SetInt(int64(*realv))
	case int8:
		v.SetKeyCached(Name, VT_Int, cache).SetInt(int64(realv))
	case *int8:
		v.SetKeyCached(Name, VT_Int, cache).SetInt(int64(*realv))
	case uint8:
		v.SetKeyCached(Name, VT_Int, cache).SetInt(int64(realv))
	case *uint8:
		v.SetKeyCached(Name, VT_Int, cache).SetInt(int64(*realv))
	case int64:
		v.SetKeyCached(Name, VT_Int, cache).SetInt(realv)
	case *int64:
		v.SetKeyCached(Name, VT_Int, cache).SetInt(int64(*realv))
	case uint64:
		v.SetKeyCached(Name, VT_Int, cache).SetInt(int64(realv))
	case *uint64:
		v.SetKeyCached(Name, VT_Int, cache).SetInt(int64(*realv))
	case string:
		v.SetKeyCached(Name, VT_String, cache).SetString(realv)
	case *DxValue:
		v.SetKeyValue(Name, realv)
	case DxValue:
		v.SetKeyValue(Name, &realv)
	case bool:
		if realv {
			v.SetKeyValue(Name, valueTrue)
		} else {
			v.SetKeyValue(Name, valueFalse)
		}
	case *bool:
		if *realv {
			v.SetKeyValue(Name, valueTrue)
		} else {
			v.SetKeyValue(Name, valueFalse)
		}
	case time.Time:
		v.SetKeyCached(Name, VT_DateTime, cache).SetTime(realv)
	case *time.Time:
		v.SetKeyCached(Name, VT_DateTime, cache).SetTime(*realv)
	case float32:
		v.SetKeyCached(Name, VT_Float, cache).SetFloat(realv)
	case *float32:
		v.SetKeyCached(Name, VT_Float, cache).SetFloat(*realv)
	case float64:
		v.SetKeyCached(Name, VT_Double, cache).SetDouble(realv)
	case *float64:
		v.SetKeyCached(Name, VT_Double, cache).SetDouble(*realv)
	case []byte:
		v.SetKeyCached(Name, VT_Binary, cache).SetBinary(realv, true)
	case *[]byte:
		v.SetKeyCached(Name, VT_Binary, cache).SetBinary(*realv, true)
	case map[string]interface{}:
		newv := v.SetKeyCached(Name, VT_Object, cache)
		for key, objv := range realv {
			newv.SetKeyvalue(key, objv, cache)
		}
	case *map[string]interface{}:
		newv := v.SetKeyCached(Name, VT_Object, cache)
		for key, objv := range *realv {
			newv.SetKeyvalue(key, objv, cache)
		}
	case map[string]string:
		newv := v.SetKeyCached(Name, VT_Object, cache)
		for key, objv := range realv {
			newv.SetKeyCached(key, VT_String, cache).SetString(objv)
		}
	case *map[string]string:
		newv := v.SetKeyCached(Name, VT_Object, v.ownercache)
		for key, objv := range *realv {
			newv.SetKeyCached(key, VT_String, cache).SetString(objv)
		}
	case map[string]int:
		newv := v.SetKeyCached(Name, VT_Object, cache)
		for key, objv := range realv {
			newv.SetKeyCached(key, VT_Int, cache).SetInt(int64(objv))
		}
	case *map[string]int:
		newv := v.SetKeyCached(Name, VT_Object, cache)
		for key, objv := range *realv {
			newv.SetKeyCached(key, VT_Int, cache).SetInt(int64(objv))
		}
	case []interface{}:
		newv := v.SetKeyCached(Name, VT_Array, cache)
		for i := 0; i < len(realv); i++ {
			newv.SetIndexvalue(i, realv[i], cache)
		}
	case *[]interface{}:
		newv := v.SetKeyCached(Name, VT_Array, cache)
		for i := 0; i < len(*realv); i++ {
			newv.SetIndexvalue(i, (*realv)[i], cache)
		}
	case []string:
		newv := v.SetKeyCached(Name, VT_Array, cache)
		for i := 0; i < len(realv); i++ {
			newv.SetIndexCached(i, VT_String, cache).SetString(realv[i])
		}
	case *[]string:
		newv := v.SetKeyCached(Name, VT_Array, cache)
		for i := 0; i < len(*realv); i++ {
			newv.SetIndexCached(i, VT_String, cache).SetString((*realv)[i])
		}
	default:
		//判断一下是否是结构体
		reflectv := reflect.ValueOf(value)
		if !reflectv.IsValid() {
			return
		}
		if reflectv.Type().Implements(ValueMarshalerType) {
			value.(DxValueMarshaler).EncodeToDxValue(v.SetKeyCached(Name, VT_Int, cache))
			return
		}
		if reflectv.Kind() == reflect.Ptr {
			reflectv = reflectv.Elem()
		}
		switch reflectv.Kind() {
		case reflect.Struct:
			rtype := reflectv.Type()
			if rtype == TimeType {
				v.SetKeyCached(Name, VT_DateTime, cache).SetTime(reflectv.Interface().(time.Time))
				return
			} else if rtype == TimePtrType {
				v.SetKeyCached(Name, VT_DateTime, cache).SetTime(*(reflectv.Interface().(*time.Time)))
				return
			}
			newv := v.SetKeyCached(Name, VT_Object, cache)
			for i := 0; i < rtype.NumField(); i++ {
				sfield := rtype.Field(i)
				fv := reflectv.Field(i)
				if fv.Kind() == reflect.Ptr {
					fv = fv.Elem()
				}
				switch fv.Kind() {
				case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
					reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
					newv.SetKeyCached(sfield.Name, VT_Int, cache).SetInt(fv.Int())
				case reflect.Bool:
					if fv.Bool() {
						newv.SetKeyValue(sfield.Name, valueTrue)
					} else {
						newv.SetKeyValue(sfield.Name, valueFalse)
					}
				case reflect.Float32:
					newv.SetKeyCached(sfield.Name, VT_Double, cache).SetFloat(float32(fv.Float()))
				case reflect.Float64:
					newv.SetKeyCached(sfield.Name, VT_Double, cache).SetDouble(fv.Float())
				case reflect.String:
					newv.SetKeyCached(sfield.Name, VT_String, cache).SetString(fv.String())
				default:
					if fv.CanInterface() {
						newv.SetKeyvalue(sfield.Name, fv.Interface(), cache)
					}
				}
			}
		case reflect.Map:
			mapRange := reflectv.MapRange()
			if !mapRange.Next() {
				return
			}
			key := mapRange.Key()
			if key.Kind() == reflect.Ptr {
				key = key.Elem()
			}
			var newV *DxValue
			kind := key.Kind()
			switch kind {
			case reflect.String:
				newV = v.SetKeyCached(Name, VT_Object, cache)
				_fillMapItem2DxValue(newV, key.String(), mapRange.Value(), cache)
				for mapRange.Next() {
					key = mapRange.Key()
					if key.Kind() == reflect.Ptr {
						key = key.Elem()
					}
					_fillMapItem2DxValue(newV, key.String(), mapRange.Value(), cache)
				}
			case reflect.Int, reflect.Int32, reflect.Int16, reflect.Int8, reflect.Int64:
				newV = v.SetKeyCached(Name, VT_Object, cache)
				_fillMapItem2DxValue(newV, strconv.FormatInt(key.Int(), 10), mapRange.Value(), cache)
				for mapRange.Next() {
					key = mapRange.Key()
					if key.Kind() == reflect.Ptr {
						key = key.Elem()
					}
					_fillMapItem2DxValue(newV, strconv.FormatInt(key.Int(), 10), mapRange.Value(), cache)
				}
			case reflect.Uint, reflect.Uint32, reflect.Uint16, reflect.Uint8, reflect.Uint64:
				newV = v.SetKeyCached(Name, VT_Object, cache)
				_fillMapItem2DxValue(newV, strconv.FormatUint(key.Uint(), 10), mapRange.Value(), cache)
				for mapRange.Next() {
					key = mapRange.Key()
					if key.Kind() == reflect.Ptr {
						key = key.Elem()
					}
					_fillMapItem2DxValue(newV, strconv.FormatUint(key.Uint(), 10), mapRange.Value(), cache)
				}
			default:
				return
			}
		case reflect.Slice:
			newv := v.SetKeyCached(Name, VT_Array, cache)
			vlen := reflectv.Len()
			for i := 0; i < vlen; i++ {
				av := reflectv.Index(i)
				realvalue := getRealValue(&av)
				if realvalue == nil {
					newv.SetIndexCached(i, VT_NULL, cache)
				} else if realvalue.CanInterface() {
					newv.SetIndexvalue(i, realvalue.Interface(), cache)
				}
			}
		}

	}
}

func (v *DxValue) SetIndexvalue(idx int, value interface{}, cache *ValueCache) {
	switch realv := value.(type) {
	case int:
		v.SetIndexCached(idx, VT_Int, cache).SetInt(int64(realv))
	case *int:
		v.SetIndexCached(idx, VT_Int, cache).SetInt(int64(*realv))
	case uint:
		v.SetIndexCached(idx, VT_Int, cache).SetInt(int64(realv))
	case *uint:
		v.SetIndexCached(idx, VT_Int, cache).SetInt(int64(*realv))
	case int32:
		v.SetIndexCached(idx, VT_Int, cache).SetInt(int64(realv))
	case *int32:
		v.SetIndexCached(idx, VT_Int, cache).SetInt(int64(*realv))
	case uint32:
		v.SetIndexCached(idx, VT_Int, cache).SetInt(int64(realv))
	case *uint32:
		v.SetIndexCached(idx, VT_Int, cache).SetInt(int64(*realv))
	case int16:
		v.SetIndexCached(idx, VT_Int, cache).SetInt(int64(realv))
	case *int16:
		v.SetIndexCached(idx, VT_Int, cache).SetInt(int64(*realv))
	case uint16:
		v.SetIndexCached(idx, VT_Int, cache).SetInt(int64(realv))
	case *uint16:
		v.SetIndexCached(idx, VT_Int, cache).SetInt(int64(*realv))
	case int8:
		v.SetIndexCached(idx, VT_Int, cache).SetInt(int64(realv))
	case *int8:
		v.SetIndexCached(idx, VT_Int, cache).SetInt(int64(*realv))
	case uint8:
		v.SetIndexCached(idx, VT_Int, cache).SetInt(int64(realv))
	case *uint8:
		v.SetIndexCached(idx, VT_Int, cache).SetInt(int64(*realv))
	case int64:
		v.SetIndexCached(idx, VT_Int, cache).SetInt(realv)
	case *int64:
		v.SetIndexCached(idx, VT_Int, cache).SetInt(*realv)
	case uint64:
		v.SetIndexCached(idx, VT_Int, cache).SetInt(int64(realv))
	case *uint64:
		v.SetIndexCached(idx, VT_Int, cache).SetInt(int64(*realv))
	case string:
		v.SetIndexCached(idx, VT_String, cache).SetString(realv)
	case *DxValue:
		v.SetIndexValue(idx, realv)
	case DxValue:
		v.SetIndexValue(idx, &realv)
	case bool:
		if realv {
			v.SetIndexValue(idx, valueTrue)
		} else {
			v.SetIndexValue(idx, valueFalse)
		}
	case *bool:
		if *realv {
			v.SetIndexValue(idx, valueTrue)
		} else {
			v.SetIndexValue(idx, valueFalse)
		}
	case time.Time:
		v.SetIndexCached(idx, VT_DateTime, cache).SetTime(realv)
	case *time.Time:
		v.SetIndexCached(idx, VT_DateTime, cache).SetTime(*realv)
	case float32:
		v.SetIndexCached(idx, VT_Float, cache).SetFloat(realv)
	case *float32:
		v.SetIndexCached(idx, VT_Float, cache).SetFloat(*realv)
	case float64:
		v.SetIndexCached(idx, VT_Double, cache).SetDouble(realv)
	case *float64:
		v.SetIndexCached(idx, VT_Double, cache).SetDouble(*realv)
	case []byte:
		v.SetIndexCached(idx, VT_Binary, cache).SetBinary(realv, true)
	case *[]byte:
		v.SetIndexCached(idx, VT_Binary, cache).SetBinary(*realv, true)
	case map[string]interface{}:
		newv := v.SetIndexCached(idx, VT_Object, cache)
		for key, objv := range realv {
			newv.SetKeyvalue(key, objv, cache)
		}
	case *map[string]interface{}:
		newv := v.SetIndexCached(idx, VT_Object, cache)
		for key, objv := range *realv {
			newv.SetKeyvalue(key, objv, cache)
		}
	case map[string]string:
		newv := v.SetIndexCached(idx, VT_Object, cache)
		for key, objv := range realv {
			newv.SetKeyCached(key, VT_String, cache).SetString(objv)
		}
	case *map[string]string:
		newv := v.SetIndexCached(idx, VT_Object, v.ownercache)
		for key, objv := range *realv {
			newv.SetKeyCached(key, VT_String, cache).SetString(objv)
		}
	case map[string]int:
		newv := v.SetIndexCached(idx, VT_Object, cache)
		for key, objv := range realv {
			newv.SetKeyCached(key, VT_Int, cache).SetInt(int64(objv))
		}
	case *map[string]int:
		newv := v.SetIndexCached(idx, VT_Object, cache)
		for key, objv := range *realv {
			newv.SetKeyCached(key, VT_Int, cache).SetInt(int64(objv))
		}
	case []interface{}:
		newv := v.SetIndexCached(idx, VT_Array, cache)
		for i := 0; i < len(realv); i++ {
			newv.SetIndexvalue(i, realv[i], cache)
		}
	case *[]interface{}:
		newv := v.SetIndexCached(idx, VT_Array, cache)
		for i := 0; i < len(*realv); i++ {
			newv.SetIndexvalue(i, (*realv)[i], cache)
		}
	case []string:
		newv := v.SetIndexCached(idx, VT_Array, cache)
		for i := 0; i < len(realv); i++ {
			newv.SetIndexCached(i, VT_String, cache).SetString(realv[i])
		}
	case *[]string:
		newv := v.SetIndexCached(idx, VT_Array, cache)
		for i := 0; i < len(*realv); i++ {
			newv.SetIndexCached(i, VT_String, cache).SetString((*realv)[i])
		}
	default:
		//判断一下是否是结构体
		reflectv := reflect.ValueOf(value)
		if !reflectv.IsValid() {
			return
		}
		rtype := reflectv.Type()
		if rtype.Implements(ValueMarshalerType) {
			value.(DxValueMarshaler).EncodeToDxValue(v.SetIndexCached(idx, VT_Int, cache))
			return
		}
		if reflectv.Kind() == reflect.Ptr {
			reflectv = reflectv.Elem()
			rtype = reflectv.Type()
		}
		switch reflectv.Kind() {
		case reflect.Struct:
			newv := v.SetIndexCached(idx, VT_Object, cache)
			for i := 0; i < rtype.NumField(); i++ {
				sfield := rtype.Field(i)
				fv := reflectv.Field(i)
				if fv.Kind() == reflect.Ptr {
					fv = fv.Elem()
				}
				switch fv.Kind() {
				case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
					reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
					newv.SetKeyCached(sfield.Name, VT_Int, cache).SetInt(fv.Int())
				case reflect.Bool:
					if fv.Bool() {
						newv.SetKeyValue(sfield.Name, valueTrue)
					} else {
						newv.SetKeyValue(sfield.Name, valueFalse)
					}
				case reflect.Float32:
					newv.SetKeyCached(sfield.Name, VT_Double, cache).SetFloat(float32(fv.Float()))
				case reflect.Float64:
					newv.SetKeyCached(sfield.Name, VT_Double, cache).SetDouble(fv.Float())
				case reflect.String:
					newv.SetKeyCached(sfield.Name, VT_String, cache).SetString(fv.String())
				default:
					if fv.CanInterface() {
						newv.SetKeyvalue(sfield.Name, fv.Interface(), cache)
					}
				}
			}
		case reflect.Map:
			mapRange := reflectv.MapRange()
			if !mapRange.Next() {
				v.SetIndexValue(idx, valueNull)
				return
			}
			key := mapRange.Key()
			if key.Kind() == reflect.Ptr {
				key = key.Elem()
			}
			kind := key.Kind()
			newv := v.SetIndexCached(idx, VT_Object, cache)
			switch kind {
			case reflect.String:
				_fillMapItem2DxValue(newv, key.String(), mapRange.Value(), cache)
				for mapRange.Next() {
					key = mapRange.Key()
					if key.Kind() == reflect.Ptr {
						key = key.Elem()
					}
					_fillMapItem2DxValue(newv, key.String(), mapRange.Value(), cache)
				}
			case reflect.Int, reflect.Int32, reflect.Int16, reflect.Int8, reflect.Int64:
				_fillMapItem2DxValue(newv, strconv.FormatInt(key.Int(), 10), mapRange.Value(), cache)
				for mapRange.Next() {
					key = mapRange.Key()
					if key.Kind() == reflect.Ptr {
						key = key.Elem()
					}
					_fillMapItem2DxValue(newv, strconv.FormatInt(key.Int(), 10), mapRange.Value(), cache)
				}
			case reflect.Uint, reflect.Uint32, reflect.Uint16, reflect.Uint8, reflect.Uint64:
				_fillMapItem2DxValue(newv, strconv.FormatUint(key.Uint(), 10), mapRange.Value(), cache)
				for mapRange.Next() {
					key = mapRange.Key()
					if key.Kind() == reflect.Ptr {
						key = key.Elem()
					}
					_fillMapItem2DxValue(newv, strconv.FormatUint(key.Uint(), 10), mapRange.Value(), cache)
				}
			}
		case reflect.Slice:
			//数组的话
			newarr := v.SetIndexCached(idx, VT_Array, cache)
			vlen := reflectv.Len()
			for i := 0; i < vlen; i++ {
				av := reflectv.Index(i)
				realvalue := getRealValue(&av)
				if realvalue == nil {
					newarr.SetIndexCached(i, VT_NULL, cache)
				} else if realvalue.CanInterface() {
					newarr.SetIndexvalue(i, realvalue.Interface(), cache)
				}
			}
		}

	}
}

//转换到标砖的数据

func (v *DxValue) ToStdValue(destv interface{}, ignoreCase bool) bool {
	switch value := destv.(type) {
	case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, string:
		return false
	case []byte:
		copy(value, v.Binary())
	case *int8:
		*value = int8(v.Int())
	case *int:
		*value = int(v.Int())
	case *int16:
		*value = int16(v.Int())
	case *int32:
		*value = int32(v.Int())
	case *int64:
		*value = v.Int()
	case *uint8:
		*value = uint8(v.Int())
	case *uint:
		*value = uint(v.Int())
	case *uint16:
		*value = uint16(v.Int())
	case *uint32:
		*value = uint32(v.Int())
	case *uint64:
		*value = uint64(v.Int())
	case *string:
		*value = v.String()
	case *[]byte:
		*value = append(*value, v.Binary()...)
	case *bool:
		*value = v.Bool()
	case *time.Time:
		*value = v.GoTime()
	case *float64:
		*value = v.Double()
	case *float32:
		*value = v.Float()
	case map[string]string:
		if v.DataType != VT_Object {
			return false
		}
		v.Visit(func(Key string, mapvalue *DxValue) bool {
			value[Key] = mapvalue.String()
			return true
		})
	case map[string]interface{}:
		if v.DataType != VT_Object {
			return false
		}
		v.Visit(func(Key string, mapvalue *DxValue) bool {
			switch mapvalue.DataType {
			case VT_Object:
				newvalue := make(map[string]interface{}, mapvalue.Count())
				mapvalue.ToStdValue(newvalue, ignoreCase)
				value[Key] = newvalue
			case VT_Array:
				newvalue := make([]interface{}, mapvalue.Count())
				mapvalue.ToStdValue(newvalue, ignoreCase)
				value[Key] = newvalue
			case VT_String, VT_RawString:
				value[Key] = mapvalue.String()
			case VT_Int:
				value[Key] = mapvalue.Int()
			case VT_DateTime:
				value[Key] = mapvalue.GoTime()
			case VT_Double:
				value[Key] = mapvalue.Double()
			case VT_Float:
				value[Key] = mapvalue.Float()
			case VT_Binary, VT_ExBinary:
				value[Key] = mapvalue.Binary()
			case VT_True:
				value[Key] = true
			case VT_False:
				value[Key] = false
			case VT_NULL:
				value[Key] = nil
			}
			return true
		})
	case []interface{}:
		if v.DataType != VT_Array {
			return false
		}
		v.Visit(func(Key string, arrvalue *DxValue) bool {
			switch arrvalue.DataType {
			case VT_Object:
				newvalue := make(map[string]interface{}, arrvalue.Count())
				arrvalue.ToStdValue(newvalue, ignoreCase)
				value = append(value, newvalue)
			case VT_Array:
				newvalue := make([]interface{}, arrvalue.Count())
				arrvalue.ToStdValue(newvalue, ignoreCase)
				value = append(value, newvalue)
			case VT_String, VT_RawString:
				value = append(value, arrvalue.String())
			case VT_Int:
				value = append(value, arrvalue.Int())
			case VT_DateTime:
				value = append(value, arrvalue.GoTime())
			case VT_Double:
				value = append(value, arrvalue.Double())
			case VT_Float:
				value = append(value, arrvalue.Float())
			case VT_Binary, VT_ExBinary:
				value = append(value, arrvalue.Binary())
			case VT_True:
				value = append(value, true)
			case VT_False:
				value = append(value, false)
			case VT_NULL:
				value = append(value, nil)
			}
			return true
		})
	case []string:
		if v.DataType != VT_Array {
			return false
		}
		v.Visit(func(Key string, arrvalue *DxValue) bool {
			value = append(value, arrvalue.String())
			return true
		})
	default:
		reflectv := reflect.ValueOf(destv)
		if !reflectv.IsValid() {
			return false
		}
		if reflectv.Kind() != reflect.Ptr {
			return false
		}
		if reflectv.Type().Implements(ValueUnMarshalerType) {
			destv.(DxValueUnMarshaler).DecodeFromDxValue(v)
			return true
		}
		reflectv = reflectv.Elem()
		valueType := reflectv.Type()

		if v.DataType != VT_Object {
			return false
		}
		//反射处理,只处理结构体
		switch valueType.Kind() {
		case reflect.Struct:
			decode2reflectFromdxValue(reflectv, v, ignoreCase, valueType)
		case reflect.Slice:
			decodeArray2reflect(reflectv, v, ignoreCase)
		default:
			return false
		}
	}
	return true
}

func _fillMapItem2DxValue(record *DxValue, key string, mapValue reflect.Value, cache *ValueCache) {
	switch mapValue.Kind() {
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		record.SetKeyCached(key, VT_Int, cache).SetInt(mapValue.Int())
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
		record.SetKeyCached(key, VT_Int, cache).SetInt(int64(mapValue.Uint()))
	case reflect.Bool:
		if mapValue.Bool() {
			record.SetKeyValue(key, valueTrue)
		} else {
			record.SetKeyValue(key, valueFalse)
		}
	case reflect.Float32:
		record.SetKeyCached(key, VT_Float, cache).SetFloat(float32(mapValue.Float()))
	case reflect.Float64:
		record.SetKeyCached(key, VT_Double, cache).SetDouble(mapValue.Float())
	case reflect.String:
		record.SetKeyCached(key, VT_String, cache).SetString(mapValue.String())
	default:
		if mapValue.CanInterface() {
			rvType := mapValue.Type()
			if rvType.Implements(ValueMarshalerType) {
				mapValue.Interface().(DxValueMarshaler).EncodeToDxValue(record.SetKeyCached(key, VT_Int, cache))
			} else if rvType == TimeType {
				record.SetKeyCached(key, VT_DateTime, cache).SetTime(mapValue.Interface().(time.Time))
			} else if rvType == TimePtrType {
				record.SetKeyCached(key, VT_DateTime, cache).SetTime(*(mapValue.Interface().(*time.Time)))
			} else {
				record.SetKeyvalue(key, mapValue.Interface(), cache)
			}
		}
	}
}

func Marshal(v interface{}) ([]byte, error) {
	switch value := v.(type) {
	case DxValue:
		return Value2Json(&value, JSE_AllEscape, true, make([]byte, 0, 128)), nil
	case *DxValue:
		return Value2Json(value, JSE_AllEscape, true, make([]byte, 0, 128)), nil
	default:
		return json.Marshal(v)
	}
}

func Unmarshal(data []byte, v interface{}) error {
	switch value := v.(type) {
	case DxValue:
		return value.LoadFromJson(data, false)
	case *DxValue:
		return value.LoadFromJson(data, false)
	default:
		return json.Unmarshal(data, v)
	}
}

func DeepCopy(v interface{}) interface{} {
	switch value := v.(type) {
	case map[string]string:
		result := make(map[string]string, len(value))
		for k, v := range value {
			result[k] = v
		}
		return result
	case map[string]interface{}:
		result := make(map[string]interface{}, len(value))
		for k, v := range value {
			result[k] = DeepCopy(v)
		}
		return result
	case map[int]string:
		result := make(map[int]string, len(value))
		for k, v := range value {
			result[k] = v
		}
		return result
	case map[int]int:
		result := make(map[int]int, len(value))
		for k, v := range value {
			result[k] = v
		}
		return result
	case map[int]struct{}:
		result := make(map[int]struct{}, len(value))
		for k, _ := range value {
			result[k] = struct{}{}
		}
		return result
	case []interface{}:
		result := make([]interface{}, len(value))
		for index, v := range value {
			result[index] = DeepCopy(v)
		}
		return result
	case int, int8, string, bool, int32, int16, uint, uint8, uint16, uint32, uint64, int64, float32, float64:
		return v
	case []byte:
		result := make([]byte, len(value))
		copy(result, value)
		return result
	case DxValue:
		switch value.DataType {
		case VT_Object:
			result := make(map[string]interface{}, value.Count())
			value.ToStdValue(&result, true)
			return result
		case VT_Array:
			result := make([]interface{}, value.Count())
			value.ToStdValue(&result, true)
			return result
		case VT_String, VT_RawString:
			return value.String()
		case VT_Int:
			return value.Int()
		case VT_Binary:
			return value.Binary()
		case VT_False:
			return false
		case VT_True:
			return true
		case VT_Double:
			return value.Double()
		case VT_Float:
			return value.Float()
		case VT_DateTime:
			return value.GoTime()
		case VT_NULL:
			return nil
		}
	default:
		reflectv := reflect.ValueOf(value)
		if !reflectv.IsValid() {
			return nil
		}
		if reflectv.Kind() == reflect.Ptr {
			reflectv = reflectv.Elem()
		}
		switch reflectv.Kind() {
		case reflect.Struct:
			return fillStructInterface(reflectv)
		case reflect.Map:
			return fillMapInterface(reflectv)
		case reflect.Slice:
			return fillSliceInterface(reflectv)
		}

	}
	return nil
}

func fillMapInterface(reflectv reflect.Value) interface{} {
	mapRange := reflectv.MapRange()
	if mapRange.Next() {
		key := mapRange.Key()
		if key.Kind() == reflect.Ptr {
			return nil
		}
		switch key.Kind() {
		case reflect.Ptr:
			return nil
		case reflect.Int, reflect.Int16, reflect.Int32, reflect.Uint, reflect.Uint16, reflect.Uint8,
			reflect.Uint32, reflect.Int8, reflect.Int64, reflect.Uint64:
			ret := make(map[int64]interface{}, 32)
			fillIntMap := func(key reflect.Value) {
				rev := mapRange.Value()
				switch rev.Kind() {
				case reflect.Int, reflect.Int16, reflect.Int32, reflect.Uint, reflect.Uint16, reflect.Uint8,
					reflect.Uint32, reflect.Int8, reflect.Int64, reflect.Uint64:
					ret[key.Int()] = rev.Int()
				case reflect.String:
					ret[key.Int()] = rev.String()
				case reflect.Bool:
					ret[key.Int()] = rev.Bool()
				case reflect.Float64, reflect.Float32:
					ret[key.Int()] = rev.Float()
				default:
					if rev.CanInterface() {
						ret[key.Int()] = DeepCopy(rev.Interface())
					}
				}
			}
			fillIntMap(key)
			for mapRange.Next() {
				fillIntMap(mapRange.Key())
			}
			return ret
		case reflect.String:
			ret := make(map[string]interface{}, 32)
			fillIntMap := func(key reflect.Value) {
				rev := mapRange.Value()
				switch rev.Kind() {
				case reflect.Int, reflect.Int16, reflect.Int32, reflect.Uint, reflect.Uint16, reflect.Uint8,
					reflect.Uint32, reflect.Int8, reflect.Int64, reflect.Uint64:
					ret[key.String()] = rev.Int()
				case reflect.String:
					ret[key.String()] = rev.String()
				case reflect.Bool:
					ret[key.String()] = rev.Bool()
				case reflect.Float64, reflect.Float32:
					ret[key.String()] = rev.Float()
				default:
					if rev.CanInterface() {
						ret[key.String()] = DeepCopy(rev.Interface())
					}
				}
			}
			fillIntMap(key)
			for mapRange.Next() {
				fillIntMap(mapRange.Key())
			}
			return ret
		}
	}
	return nil
}

func fillStructInterface(reflectv reflect.Value) interface{} {
	tp := reflectv.Type()
	if tp == TimeType {
		return reflectv.Interface()
	} else if tp == TimePtrType {
		vi := reflectv.Interface()
		return *(vi.(*time.Time))
	}
	rtype := reflectv.Type()
	result := make(map[string]interface{}, rtype.NumField())
	for i := 0; i < rtype.NumField(); i++ {
		sfield := rtype.Field(i)
		fv := reflectv.Field(i)
		if fv.Kind() == reflect.Ptr {
			fv = fv.Elem()
		}
		switch fv.Kind() {
		case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
			reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
			result[sfield.Name] = fv.Int()
		case reflect.Bool:
			result[sfield.Name] = fv.Bool()
		case reflect.Float32, reflect.Float64:
			result[sfield.Name] = fv.Float()
		case reflect.String:
			result[sfield.Name] = fv.String()
		default:
			if fv.CanInterface() {
				result[sfield.Name] = DeepCopy(fv.Interface())
			}
		}
	}
	return result
}

func fillSliceInterface(reflectv reflect.Value) interface{} {
	vlen := reflectv.Len()
	if vlen == 0 {
		return nil
	}
	av := reflectv.Index(0)
	realValue := getRealValue(&av)
	if realValue == nil {
		return nil
	}
	switch realValue.Kind() {
	case reflect.Int, reflect.Int64, reflect.Int16, reflect.Int8, reflect.Uint, reflect.Uint64, reflect.Uint16, reflect.Uint8:
		result := make([]int64, vlen)
		result[0] = av.Int()
		for i := 1; i < vlen; i++ {
			av = reflectv.Index(i)
			realValue = getRealValue(&av)
			if realValue != nil {
				result[i] = realValue.Int()
			}
		}
		return result
	case reflect.String:
		result := make([]string, vlen)
		result[0] = av.String()
		for i := 1; i < vlen; i++ {
			av = reflectv.Index(i)
			realValue = getRealValue(&av)
			if realValue != nil {
				result[i] = realValue.String()
			}
		}
		return result
	case reflect.Bool:
		result := make([]bool, vlen)
		result[0] = av.Bool()
		for i := 1; i < vlen; i++ {
			av = reflectv.Index(i)
			realValue = getRealValue(&av)
			if realValue != nil {
				result[i] = realValue.Bool()
			}
		}
		return result
	case reflect.Float64, reflect.Float32:
		result := make([]float64, vlen)
		result[0] = av.Float()
		for i := 1; i < vlen; i++ {
			av = reflectv.Index(i)
			realValue = getRealValue(&av)
			if realValue != nil {
				result[i] = realValue.Float()
			}
		}
		return result
	default:
		if av.CanInterface() {
			result := make([]interface{}, vlen)
			result[0] = DeepCopy(av.Interface())
			for i := 1; i < vlen; i++ {
				av = reflectv.Index(i)
				realValue = getRealValue(&av)
				if realValue != nil {
					result[i] = DeepCopy(av.Interface())
				}
			}
			return result
		}
		return nil
	}
}

func IntValue(v interface{}) (int64, bool) {
	switch value := v.(type) {
	case string:
		result, err := DxCommonLib.ParseInt64(value)
		if err != nil {
			return 0, false
		}
		return result, true
	case int:
		return int64(value), true
	case *int:
		return int64(*value), true
	case *int32:
		return int64(*value), true
	case int16:
		return int64(value), true
	case *int16:
		return int64(*value), true
	case uint:
		return int64(value), true
	case *uint:
		return int64(*value), true
	case *uint32:
		return int64(*value), true
	case uint16:
		return int64(value), true
	case *uint16:
		return int64(*value), true
	case int8:
		return int64(value), true
	case *int8:
		return int64(*value), true
	case uint8:
		return int64(value), true
	case *uint8:
		return int64(*value), true
	case bool:
		return int64(DxCommonLib.Ord(value)), true
	case *bool:
		return int64(DxCommonLib.Ord(*value)), true
	case float64:
		return int64(value), true
	case float32:
		return int64(value), true
	default:
		return 0, false
	}
}

func BytesValue(v interface{}) ([]byte, bool) {
	switch value := v.(type) {
	case string:
		return DxCommonLib.FastString2Byte(value), true
	case *string:
		return DxCommonLib.FastString2Byte(*value), true
	case *DxValue:
		return value.Binary(), true
	case []byte:
		return value, true
	case *[]byte:
		return *value, true
	default:
		return nil, false
	}
}

func StringValue(v interface{}) (string, bool) {
	switch value := v.(type) {
	case int:
		return strconv.FormatInt(int64(value), 10), true
	case int8:
		return strconv.FormatInt(int64(value), 10), true
	case int16:
		return strconv.FormatInt(int64(value), 10), true
	case int32:
		return strconv.FormatInt(int64(value), 10), true
	case int64:
		return strconv.FormatInt(value, 10), true
	case uint:
		return strconv.FormatUint(uint64(value), 10), true
	case uint8:
		return strconv.FormatUint(uint64(value), 10), true
	case uint16:
		return strconv.FormatUint(uint64(value), 10), true
	case uint32:
		return strconv.FormatUint(uint64(value), 10), true
	case uint64:
		return strconv.FormatUint(value, 10), true
	case bool:
		if value {
			return "true", true
		}
		return "false", true
	case float32:
		return strconv.FormatFloat(float64(value), 'f', -1, 32), true
	case float64:
		return strconv.FormatFloat(value, 'f', -1, 32), true
	case *int:
		return strconv.FormatInt(int64(*value), 10), true
	case *int8:
		return strconv.FormatInt(int64(*value), 10), true
	case *int16:
		return strconv.FormatInt(int64(*value), 10), true
	case *int32:
		return strconv.FormatInt(int64(*value), 10), true
	case *int64:
		return strconv.FormatInt(*value, 10), true
	case *uint:
		return strconv.FormatUint(uint64(*value), 10), true
	case *uint8:
		return strconv.FormatUint(uint64(*value), 10), true
	case *uint16:
		return strconv.FormatUint(uint64(*value), 10), true
	case *uint32:
		return strconv.FormatUint(uint64(*value), 10), true
	case *uint64:
		return strconv.FormatUint(*value, 10), true
	case *bool:
		if *value {
			return "true", true
		}
		return "false", true
	case *float32:
		return strconv.FormatFloat(float64(*value), 'f', -1, 32), true
	case *float64:
		return strconv.FormatFloat(*value, 'f', -1, 32), true
	case string:
		return value, true

	case *string:
		return *value, true
	case []byte:
		return string(value), true
	case *[]byte:
		return string(*value), true
	default:
		return "", false
	}
}

func DeepAssignTo(source, dest interface{}) bool {
	//dest必须是指针
	switch value := dest.(type) {
	case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, string:
		return false
	case *int8:
		intv, ok := IntValue(source)
		if ok {
			*value = int8(intv)
		}
		return ok
	case *int16:
		intv, ok := IntValue(source)
		if ok {
			*value = int16(intv)
		}
		return ok
	case *int32:
		intv, ok := IntValue(source)
		if ok {
			*value = int32(intv)
		}
		return ok
	case *int64:
		intv, ok := IntValue(source)
		if ok {
			*value = intv
		}
		return ok
	case DxValue:
		value.ToStdValue(dest, true)
	case *DxValue:
		value.ToStdValue(dest, true)
	case *uint8:
		intv, ok := IntValue(source)
		if ok {
			*value = uint8(intv)
		}
		return ok
	case *uint16:
		intv, ok := IntValue(source)
		if ok {
			*value = uint16(intv)
		}
		return ok
	case *uint32:
		intv, ok := IntValue(source)
		if ok {
			*value = uint32(intv)
		}
		return ok
	case *uint64:
		intv, ok := IntValue(source)
		if ok {
			*value = uint64(intv)
		}
		return ok
	case []byte:
		bytes, ok := BytesValue(source)
		if ok {
			copy(value, bytes)
		}
		return ok
	case *[]byte:
		bytes, ok := BytesValue(source)
		if ok {
			*value = append(*value, bytes...)
		}
		return ok
	case *bool:
		switch bv := source.(type) {
		case string:
			*value = strings.EqualFold(bv, "true")
			return true
		case bool:
			*value = bv
			return true

		}
	case *string:
		strv, ok := StringValue(source)
		if ok {
			*value = strv
		}
		return ok
	default:
		//使用反射处理
		if dxv, ok := source.(*DxValue); ok {
			return dxv.ToStdValue(dest, true)
		}
		reflectv := reflect.ValueOf(dest)
		if !reflectv.IsValid() {
			return false
		}
		if reflectv.Kind() != reflect.Ptr {
			return false
		}
		reflectv = reflectv.Elem()
		valueType := reflectv.Type()
		sourcev := reflect.ValueOf(source)
		realSource := getRealValue(&sourcev)
		switch valueType.Kind() {
		case reflect.Struct:
			switch realSource.Kind() {
			case reflect.Struct:
				return _convertStruct2Struct(realSource, &reflectv)
			case reflect.Map:
				return _convertMap2Struct(realSource, &reflectv)
			default:
				return false
			}
		case reflect.Slice:
			if realSource.Kind() != reflect.Slice {
				return false
			}
			_convertSlice2Slice(realSource, &reflectv)
		case reflect.Interface:
			switch realSource.Kind() {
			case reflect.Interface:
				//interface->interface
				if realSource.CanInterface() {
					reflectv.Set(reflect.ValueOf(realSource.Interface()))
					return true
				}
				return false
			case reflect.Slice:
				newV := reflect.MakeSlice(realSource.Type(), realSource.Len(), realSource.Len())
				if !_convertSlice2Slice(realSource, &newV) {
					return false
				}
				reflectv.Set(newV)
			case reflect.Map:
				newV := reflect.MakeMapWithSize(realSource.Type(), realSource.Len())
				if !_convertMap2Map(realSource, &newV) {
					return false
				}
				reflectv.Set(newV)
			case reflect.Struct:
				newV := reflect.New(realSource.Type()).Elem()
				if !_convertStruct2Struct(realSource, &newV) {
					return false
				}
				reflectv.Set(newV)
			default:
				if realSource.CanInterface() {
					reflectv.Set(reflect.ValueOf(realSource.Interface()))
					return true
				}
				return false
			}
		case reflect.Map:
			switch realSource.Kind() {
			case reflect.Map:
				//Map->Map
				return _convertMap2Map(realSource, &reflectv)
			case reflect.Struct:
				//struct->Map
				return _convertStruct2Map(realSource, &reflectv)
			default:
				return false
			}
		default:
			return false
		}
	}
	return true
}

func _convertMap2Map(source, dest *reflect.Value) bool {
	mapType := dest.Type()
	if mapType == nil {
		return false
	}
	destKeyType := mapType.Key()
	destKeyKind := destKeyType.Kind()
	if !DxCommonLib.IsSimpleCopyKind(destKeyKind) && destKeyKind != reflect.Interface {
		return false
	}
	srcType := source.Type()
	destTyp := dest.Type()
	destMapValueType := mapType.Elem()
	if srcType == destTyp {
		mapRange := source.MapRange()
		valueKind := destMapValueType.Kind()
		if DxCommonLib.IsSimpleCopyKind(valueKind) || valueKind == reflect.Interface {
			for mapRange.Next() {
				dest.SetMapIndex(mapRange.Key(), mapRange.Value())
			}
			return true
		}
		switch valueKind {
		case reflect.Map:
			for mapRange.Next() {
				mapV := mapRange.Value()
				newV := reflect.MakeMapWithSize(mapV.Type(), mapV.Len())
				_convertMap2Map(&mapV, &newV)
				dest.SetMapIndex(mapRange.Key(), newV)
			}
			return true
		case reflect.Slice:
			destSliceVType := destMapValueType.Elem()
			destKind := destSliceVType.Kind()
			if DxCommonLib.IsSimpleCopyKind(destKind) || destKind == reflect.Interface {
				for mapRange.Next() {
					mapV := mapRange.Value()
					newV := reflect.MakeSlice(mapV.Type(), mapV.Len(), mapV.Len())
					for i := 0; i < mapV.Len(); i++ {
						newV.Index(i).Set(mapV.Index(i))
					}
					dest.SetMapIndex(mapRange.Key(), newV)
				}
				return true
			}
		case reflect.Struct:
			for mapRange.Next() {
				mapV := mapRange.Value()
				newV := reflect.New(mapV.Type()).Elem()
				_convertStruct2Struct(&mapV, &newV)
				dest.SetMapIndex(mapRange.Key(), newV)
			}
			return true
		}
		return false
	}
	srcKeyType := srcType.Key()
	srcKeyKind := srcKeyType.Kind()
	srcValueType := srcType.Elem()
	srcValueKind := srcValueType.Kind()
	destValueKind := destMapValueType.Kind()
	if srcKeyKind != destKeyKind && srcKeyKind == reflect.Interface ||
		srcValueKind == reflect.Interface && destValueKind != reflect.Interface {
		//无法从interface->转换到具体类型
		return false
	}
	if srcKeyKind == destKeyKind || srcKeyKind == reflect.Interface && DxCommonLib.IsSimpleCopyKind(destKeyKind) ||
		destKeyKind == reflect.Interface && DxCommonLib.IsSimpleCopyKind(srcKeyKind) {
		getKeyValue := func(keyValue reflect.Value) reflect.Value {
			if srcKeyKind != destKeyKind {
				if destKeyKind == reflect.Interface {
					if DxCommonLib.IsSimpleCopyKind(srcKeyKind) {
						return reflect.ValueOf(keyValue.Interface())
					}
				}
			}
			return keyValue
		}
		mapRange := source.MapRange()
		if DxCommonLib.IsSimpleCopyKind(srcValueKind) {
			if srcValueKind == destValueKind || destValueKind == reflect.Interface {
				for mapRange.Next() {
					dest.SetMapIndex(getKeyValue(mapRange.Key()), mapRange.Value())
				}
				return true
			}
			return false
		}

		switch destValueKind {
		case reflect.Map:
			switch srcValueKind {
			case reflect.Map:
				for mapRange.Next() {
					mapV := mapRange.Value()
					newV := reflect.MakeMapWithSize(destMapValueType, mapV.Len())
					if _convertMap2Map(&mapV, &newV) {
						dest.SetMapIndex(getKeyValue(mapRange.Key()), newV)
					}
				}
				return true
			case reflect.Struct:
				//struct->Map
				for mapRange.Next() {
					mapV := mapRange.Value()
					newV := reflect.MakeMapWithSize(destMapValueType, mapV.Len())
					if _convertStruct2Map(&mapV, &newV) {
						dest.SetMapIndex(getKeyValue(mapRange.Key()), newV)
					}
				}
				return true
			default:
				return false
			}
		case reflect.Slice:
			if srcValueKind != reflect.Slice {
				return false
			}
			//都是切片，但是切片类型不同
			srcSliceValueType := srcValueType.Elem()
			srcKind := srcSliceValueType.Kind()
			destSliceValueType := destMapValueType.Elem()
			destKind := destSliceValueType.Kind()
			if destKind == reflect.Interface {
				if DxCommonLib.IsSimpleCopyKind(srcKind) {
					for mapRange.Next() {
						mapV := mapRange.Value()
						newV := reflect.MakeSlice(destMapValueType, mapV.Len(), mapV.Len())
						for i := 0; i < mapV.Len(); i++ {
							newV.Index(i).Set(mapV.Index(i))
						}
						dest.SetMapIndex(getKeyValue(mapRange.Key()), newV)
					}
					return true
				}
				switch srcKind {
				case reflect.Map:
					for mapRange.Next() {
						mapV := mapRange.Value()
						newV := reflect.MakeSlice(destMapValueType, mapV.Len(), mapV.Len())
						for i := 0; i < mapV.Len(); i++ {
							//创建类型
							sourceValue := mapV.Index(i)
							v := reflect.MakeMapWithSize(srcSliceValueType, sourceValue.Len())
							if _convertMap2Map(&sourceValue, &v) {
								newV.Index(i).Set(v)
							}
						}
						dest.SetMapIndex(getKeyValue(mapRange.Key()), newV)
					}
				case reflect.Slice:
					for mapRange.Next() {
						mapV := mapRange.Value()
						newV := reflect.MakeSlice(destMapValueType, mapV.Len(), mapV.Len())
						for i := 0; i < mapV.Len(); i++ {
							//创建类型
							sourceValue := mapV.Index(i)
							l := sourceValue.Len()
							v := reflect.MakeSlice(srcSliceValueType, l, l)
							if _convertSlice2Slice(&sourceValue, &v) {
								newV.Index(i).Set(v)
							}
						}
						dest.SetMapIndex(getKeyValue(mapRange.Key()), newV)
					}
				case reflect.Struct:
					for mapRange.Next() {
						mapV := mapRange.Value()
						newV := reflect.MakeSlice(destMapValueType, mapV.Len(), mapV.Len())
						for i := 0; i < mapV.Len(); i++ {
							//创建类型
							v := reflect.New(srcSliceValueType).Elem()
							sourceValue := mapV.Index(i)
							if _convertStruct2Struct(&sourceValue, &v) {
								newV.Index(i).Set(v)
							}
						}
						dest.SetMapIndex(getKeyValue(mapRange.Key()), newV)
					}
				default:
					return false
				}
				return true
			}
			if DxCommonLib.IsSimpleCopyKind(destKind) && srcKind == reflect.Interface {
				for mapRange.Next() {
					mapV := mapRange.Value()
					newV := reflect.MakeSlice(destMapValueType, mapV.Len(), mapV.Len())
					for i := 0; i < mapV.Len(); i++ {
						newV.Index(i).Set(reflect.ValueOf(mapV.Index(i).Interface()))
					}
					dest.SetMapIndex(getKeyValue(mapRange.Key()), newV)
				}
				return true
			}
		case reflect.Struct:
			if srcValueKind == reflect.Struct {
				//都是结构体
				for mapRange.Next() {
					mapV := mapRange.Value()
					newV := reflect.New(destMapValueType).Elem()
					if !_convertStruct2Struct(&mapV, &newV) {
						return false
					}
					dest.SetMapIndex(getKeyValue(mapRange.Key()), newV)
				}
				return true
			}
			if srcValueKind != reflect.Map {
				return false
			}
			//map->struct
			for mapRange.Next() {
				mapV := mapRange.Value()
				newV := reflect.New(destMapValueType).Elem()
				if !_convertMap2Struct(&mapV, &newV) {
					return false
				}
				dest.SetMapIndex(getKeyValue(mapRange.Key()), newV)
			}
			return true
		}
	}
	return false
}

func _convertStruct2Map(source, dest *reflect.Value) bool {
	//dest的MapKey必须是字符串或者interface
	mapType := dest.Type()
	mapKeyType := mapType.Key().Kind()
	if mapKeyType != reflect.String && mapKeyType != reflect.Interface {
		return false
	}
	getMapKey := func(srcField *reflect.StructField) reflect.Value {
		fieldTags := DxCommonLib.ParseStructTag(string(srcField.Tag))
		keyName := ""
		var hasTag bool
		if fieldTags != nil {
			keyName, hasTag = fieldTags["map"]
			if !hasTag {
				keyName, hasTag = fieldTags["json"]
				if !hasTag {
					keyName, hasTag = fieldTags["yaml"]
				}
			}
			if !hasTag {
				keyName, hasTag = fieldTags["msgpack"]
			}
			if !hasTag {
				for _, v := range fieldTags {
					hasTag = true
					keyName = v
					break
				}
			}
		}
		if keyName == "" {
			keyName = srcField.Name
		}
		if mapKeyType == reflect.String {
			v := reflect.Value{}
			v.SetString(keyName)
			return v
		}
		return reflect.ValueOf(keyName)
	}
	srcType := source.Type()
	mapValueType := mapType.Elem()
	mapVkind := mapValueType.Kind()
	for i := 0; i < srcType.NumField(); i++ {
		srcField := srcType.Field(i)
		if !srcField.IsExported() {
			continue
		}
		switch srcField.Type.Kind() {
		case reflect.Struct:
			switch mapVkind {
			case reflect.Map:
				srcV := source.Field(i)
				newV := reflect.MakeMapWithSize(mapValueType, srcV.Len())
				if _convertStruct2Map(&srcV, &newV) {
					dest.SetMapIndex(getMapKey(&srcField), newV)
				}
			case reflect.Struct:
				srcV := source.Field(i)
				newV := reflect.New(mapValueType).Elem()
				if _convertStruct2Struct(&srcV, &newV) {
					dest.SetMapIndex(getMapKey(&srcField), newV)
				}
			case reflect.Interface:
				srcV := source.Field(i)
				newV := reflect.New(srcField.Type).Elem()
				_convertStruct2Struct(&srcV, &newV)
				dest.SetMapIndex(getMapKey(&srcField), newV)
			default:
				return false
			}
		case reflect.Map:
			switch mapVkind {
			case reflect.Map:
				srcV := source.Field(i)
				newV := reflect.MakeMapWithSize(mapValueType, srcV.Len())
				if !_convertMap2Map(&srcV, &newV) {
					return false
				}
				dest.SetMapIndex(getMapKey(&srcField), newV)
			case reflect.Struct:
				srcV := source.Field(i)
				newV := reflect.New(mapValueType).Elem()
				if !_convertMap2Struct(&srcV, &newV) {
					return false
				}
				dest.SetMapIndex(getMapKey(&srcField), newV)
			case reflect.Interface:
				srcV := source.Field(i)
				newV := reflect.MakeMapWithSize(srcField.Type, srcV.Len())
				if !_convertMap2Map(&srcV, &newV) {
					return false
				}
				dest.SetMapIndex(getMapKey(&srcField), newV)
			default:
				return false
			}
		case reflect.Slice:
			if mapVkind != reflect.Slice {
				return false
			}
			srcV := source.Field(i)
			newV := reflect.MakeSlice(mapValueType, srcV.Len(), srcV.Len())
			if !_convertSlice2Slice(&srcV, &newV) {
				return false
			}
			dest.SetMapIndex(getMapKey(&srcField), newV)
		default:
			if srcField.Type.Kind() != mapVkind {
				return false
			}
			if DxCommonLib.IsSimpleCopyKind(mapVkind) {
				dest.SetMapIndex(getMapKey(&srcField), source.Field(i))
			} else if mapVkind == reflect.Interface {
				srcV := source.Field(i)
				if srcV.CanInterface() {
					dest.SetMapIndex(getMapKey(&srcField), reflect.ValueOf(DeepCopy(srcV.Interface())))
				}
			}
		}
	}
	return true
}

func _convertMap2Struct(source, dest *reflect.Value) bool {
	mapKeyType := source.Type().Key()
	if mapKeyType.Kind() != reflect.String {
		return false
	}
	mapRange := source.MapRange()
	destType := dest.Type()
	for mapRange.Next() {
		key := mapRange.Key().String()
		for i := 0; i < destType.NumField(); i++ {
			field := destType.Field(i)
			if !field.IsExported() {
				continue
			}
			if !DxCommonLib.CanKeyMatchStructField(key, &field) {
				continue
			}
			//匹配上了，然后查看类型是否能匹配
			sourceV := mapRange.Value()
			if field.Type == sourceV.Type() {
				if DxCommonLib.IsSimpleCopyKind(field.Type.Kind()) {
					dest.Field(i).Set(sourceV)
					continue
				}
			}
			switch sourceV.Kind() {
			case reflect.Map:
				switch field.Type.Kind() {
				case reflect.Map:
					newV := reflect.MakeMapWithSize(field.Type, sourceV.Len())
					if _convertMap2Map(&sourceV, &newV) {
						dest.Field(i).Set(newV)
					}
				case reflect.Struct:
					newV := reflect.New(field.Type).Elem()
					if _convertMap2Struct(&sourceV, &newV) {
						dest.Field(i).Set(newV)
					}
				case reflect.Interface:
					newV := reflect.MakeMapWithSize(sourceV.Type(), sourceV.Len())
					if _convertMap2Map(&sourceV, &newV) {
						dest.Field(i).Set(newV)
					}
				default:
					return false
				}
			case reflect.Struct:
				switch field.Type.Kind() {
				case reflect.Map:
					newV := reflect.MakeMapWithSize(field.Type, sourceV.Len())
					if _convertStruct2Map(&sourceV, &newV) {
						dest.Field(i).Set(newV)
					}
				case reflect.Struct:
					newV := reflect.New(field.Type).Elem()
					if _convertStruct2Struct(&sourceV, &newV) {
						dest.Field(i).Set(newV)
					}
				case reflect.Interface:
					newV := reflect.New(sourceV.Type()).Elem()
					if _convertStruct2Struct(&sourceV, &newV) {
						dest.Field(i).Set(newV)
					}
				default:
					return false
				}
			case reflect.Slice:
			default:
				if field.Type != InterfaceType || !sourceV.CanInterface() {
					return false
				}
				dest.Field(i).Set(reflect.ValueOf(sourceV.Interface()))
			}
		}
	}
	return true
}

func _convertSlice2Slice(source, dest *reflect.Value) bool {
	n := source.Len()
	vType := dest.Type().Elem()
	if dest.Len() < n {
		dest.Set(growSliceValue(*dest, n))
	}
	destKind := vType.Kind()
	srcType := source.Type().Elem()
	if destKind == reflect.Interface {
		switch srcType.Kind() {
		case reflect.Map:
			for j := 0; j < n; j++ {
				sv := source.Index(j)
				v := reflect.MakeMapWithSize(vType, sv.Len())
				if _convertMap2Map(&sv, &v) {
					dest.Index(j).Set(v)
				}
			}
			return true
		case reflect.Struct:
			for j := 0; j < n; j++ {
				sv := source.Index(j)
				v := reflect.New(vType).Elem()
				if _convertStruct2Struct(&sv, &v) {
					dest.Index(j).Set(v)
				}
			}
			return true
		case reflect.Slice:
			for j := 0; j < n; j++ {
				sv := source.Index(j)
				l := sv.Len()
				v := reflect.MakeSlice(vType, l, l)
				if _convertSlice2Slice(&sv, &v) {
					dest.Index(j).Set(v)
				}
			}
			return true
		case reflect.Interface:
			for j := 0; j < n; j++ {
				sv := source.Index(j)
				dest.Index(j).Set(reflect.ValueOf(sv.Interface()))
			}
			return true
		default:
			if DxCommonLib.IsSimpleCopyKind(srcType.Kind()) {
				for j := 0; j < n; j++ {
					sv := source.Index(j)
					dest.Index(j).Set(reflect.ValueOf(sv.Interface()))
				}
				return true
			}
			return false
		}
	}
	switch destKind {
	case reflect.String, reflect.Int, reflect.Int64, reflect.Int8, reflect.Int16, reflect.Int32,
		reflect.Uint, reflect.Uint64, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Float32,
		reflect.Float64, reflect.Bool:
		if srcType == vType {
			for j := 0; j < n; j++ {
				dest.Index(j).Set(source.Index(j))
			}
			return true
		}
	case reflect.Struct:
		switch srcType.Kind() {
		case reflect.Struct:
			for j := 0; j < n; j++ {
				srv := source.Index(j)
				dstv := dest.Index(j)
				_convertStruct2Struct(&srv, &dstv)
			}
			return true
		case reflect.Map:
			for j := 0; j < n; j++ {
				srv := source.Index(j)
				dstv := dest.Index(j)
				_convertMap2Struct(&srv, &dstv)
			}
			return true
		default:
			return false
		}
	case reflect.Map:
		switch srcType.Kind() {
		case reflect.Map:
			for j := 0; j < n; j++ {
				srv := source.Index(j)
				dstv := dest.Index(j)
				_convertMap2Map(&srv, &dstv)
			}
			return true
		case reflect.Struct:
			for j := 0; j < n; j++ {
				srv := source.Index(j)
				dstv := dest.Index(j)
				_convertStruct2Map(&srv, &dstv)
			}
			return true
		default:
			return false
		}
	case reflect.Slice:
		if srcType.Kind() != reflect.Slice {
			return false
		}
		for j := 0; j < n; j++ {
			srv := source.Index(j)
			dstv := dest.Index(j)
			_convertSlice2Slice(&srv, &dstv)
		}
	default:
		return false
	}
	return true
}

func _convertStruct2Struct(source, dest *reflect.Value) bool {
	srcType := source.Type()
	destTyp := dest.Type()
	if srcType == destTyp {
		if srcType == TimeType {
			dest.Set(*source)
			return true
		} else if srcType == TimePtrType {
			dest.Set(source.Elem())
			return true
		}
		for i := 0; i < srcType.NumField(); i++ {
			fld := srcType.Field(i)
			//直接一一匹配,先看看是否是导出的
			if !fld.IsExported() {
				continue
			}
			childreflectv := dest.Field(i)
			sourceV := source.Field(i)
			switch fld.Type.Kind() {
			case reflect.String, reflect.Int, reflect.Int64, reflect.Int8, reflect.Int16, reflect.Int32,
				reflect.Uint, reflect.Uint64, reflect.Uint8, reflect.Uint16, reflect.Uint32,
				reflect.Float32, reflect.Float64, reflect.Bool:
				childreflectv.Set(sourceV)
			case reflect.Slice:
				n := sourceV.Len()
				if n > 0 {
					vslice := reflect.MakeSlice(fld.Type, n, n)
					_convertSlice2Slice(&sourceV, &vslice)
					childreflectv.Set(vslice)
				}
			case reflect.Struct:
				newV := reflect.New(sourceV.Type()).Elem()
				_convertStruct2Struct(&sourceV, &newV)
				childreflectv.Set(newV)
			case reflect.Map:
				newV := reflect.MakeMapWithSize(sourceV.Type(), sourceV.Len())
				_convertMap2Map(&sourceV, &newV)
				childreflectv.Set(newV)
			case reflect.Interface:
				if sourceV.CanInterface() {
					childreflectv.Set(reflect.ValueOf(DeepCopy(sourceV.Interface())))
					return true
				}
				return false
			default:
				return false
			}
		}
		return true
	}
	for i := 0; i < srcType.NumField(); i++ {
		srcField := srcType.Field(i)
		if !srcField.IsExported() {
			continue
		}
		for j := 0; j < destTyp.NumField(); j++ {
			destField := destTyp.Field(j)
			//判顶一下是否是导出的
			if !destField.IsExported() {
				continue
			}
			if !DxCommonLib.CanConvertStructField(&srcField, &destField) {
				continue
			}
			srcV := source.Field(i)
			childreflectv := dest.Field(i)
			srvKind := srcV.Kind()
			destVKind := destField.Type.Kind()
			switch srvKind {
			case reflect.String, reflect.Int, reflect.Int64, reflect.Int8, reflect.Int16, reflect.Int32,
				reflect.Uint, reflect.Uint64, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Float32,
				reflect.Float64, reflect.Bool:
				if destVKind == srvKind {
					childreflectv.Set(srcV)
				} else if destVKind == reflect.Interface {
					childreflectv.Set(reflect.ValueOf(srcV.Interface()))
				}
			case reflect.Struct:
				switch destVKind {
				case reflect.Struct:
					newV := reflect.New(destField.Type).Elem()
					if _convertStruct2Struct(&srcV, &newV) {
						childreflectv.Set(newV)
					}
				case reflect.Map:
					newV := reflect.MakeMapWithSize(destField.Type, srcV.Len())
					if _convertStruct2Map(&srcV, &newV) {
						childreflectv.Set(newV)
					}
				}
			case reflect.Map:
				switch destVKind {
				case reflect.Struct:
					newV := reflect.New(destField.Type).Elem()
					if _convertMap2Struct(&srcV, &newV) {
						childreflectv.Set(newV)
					}
				case reflect.Map:
					newV := reflect.MakeMapWithSize(destField.Type, srcV.Len())
					if _convertMap2Map(&srcV, &newV) {
						childreflectv.Set(newV)
					}
				}
			case reflect.Slice:
				if destVKind != reflect.Slice {
					return false
				}
				if srcV.Len() == 0 {
					return true
				}
				//转换切片
				newV := reflect.MakeSlice(destField.Type, srcV.Len(), srcV.Len())
				if _convertSlice2Slice(&srcV, &newV) {
					childreflectv.Set(newV)
				}
			case reflect.Interface:
				switch destVKind {
				case reflect.Interface:
					if !srcV.CanInterface() {
						return false
					}
					childreflectv.Set(reflect.ValueOf(DeepCopy(srcV.Interface())))
				case reflect.String:
					v := srcV.Interface()
					switch sValue := v.(type) {
					case string:
						childreflectv.SetString(sValue)
					case int:
						childreflectv.SetString(strconv.Itoa(sValue))
					case int64:
						childreflectv.SetString(strconv.FormatInt(sValue, 10))
					case bool:
						if sValue {
							childreflectv.SetString("true")
						} else {
							childreflectv.SetString("false")
						}
					case int8:
						childreflectv.SetString(strconv.FormatInt(int64(sValue), 10))
					case int16:
						childreflectv.SetString(strconv.FormatInt(int64(sValue), 10))
					case int32:
						childreflectv.SetString(strconv.FormatInt(int64(sValue), 10))
					case uint:
						childreflectv.SetString(strconv.FormatUint(uint64(sValue), 10))
					case uint8:
						childreflectv.SetString(strconv.FormatUint(uint64(sValue), 10))
					case uint16:
						childreflectv.SetString(strconv.FormatUint(uint64(sValue), 10))
					case uint32:
						childreflectv.SetString(strconv.FormatUint(uint64(sValue), 10))
					case uint64:
						childreflectv.SetString(strconv.FormatUint(sValue, 10))
					}
				case reflect.Int:
					v := srcV.Interface()
					switch sValue := v.(type) {
					case int:
						childreflectv.SetInt(int64(sValue))
					case int64:
						childreflectv.SetInt(sValue)
					case uint:
						childreflectv.SetInt(int64(sValue))
					case int8:
						childreflectv.SetInt(int64(sValue))
					case int32:
						childreflectv.SetInt(int64(sValue))
					case uint32:
						childreflectv.SetInt(int64(sValue))
					case uint16:
						childreflectv.SetInt(int64(sValue))
					case int16:
						childreflectv.SetInt(int64(sValue))
					case uint8:
						childreflectv.SetInt(int64(sValue))
					case string:
						if v64, err := DxCommonLib.ParseInt64(sValue); err == nil {
							childreflectv.SetInt(v64)
						}
					default:
						return false
					}
				case reflect.Bool:
					v := srcV.Interface()
					switch sValue := v.(type) {
					case string:
						childreflectv.SetBool(strings.EqualFold(sValue, "true"))
					case int:
						childreflectv.SetBool(sValue != 0)
					case uint:
						childreflectv.SetBool(sValue != 0)
					case int8:
						childreflectv.SetBool(sValue != 0)
					case int16:
						childreflectv.SetBool(sValue != 0)
					case int32:
						childreflectv.SetBool(sValue != 0)
					case int64:
						childreflectv.SetBool(sValue != 0)
					case uint8:
						childreflectv.SetBool(sValue != 0)
					case uint16:
						childreflectv.SetBool(sValue != 0)
					case uint64:
						childreflectv.SetBool(sValue != 0)
					default:
						return false
					}
				default:
					return false
				}
			}
			break
		}
	}
	return true
}
